* Table A29:  Summary Statistics by Survey Weight

* Note that "Dropped due to NLS66 Parent Age Constraints" shows up as first row, but is 5th row in table

clear
use "${data_dir}DavisMazumderData.dta"

keep if age_firstSurvey<=18
drop if miss0 | miss1


replace weight = weight/100000 if survey==1966
replace weight = weight/1000 if survey==1979

gen high_weight = weight>=2.8 if survey==1966
 replace high_weight = weight>=3.6 if survey==1979
 
keep if high_weight==0

gen dad_present = dad_age_b<. 
gen mom_present = mom_age_b<. 
gen spouse_present = spouse_age<.

gen keep =  !((mom_outOfRange==1 & linkMom==1 & !(dad_outOfRange==0 & linkDad==1)) | (dad_outOfRange==1 & linkDad==1 & !(mom_outOfRange==0 & linkMom==1)) | (linkMom==0 & linkDad==0) ) 
gen drop = 1-keep


quietly {
mat sumstat = ., ., ., ., ., .
mat sumstat_w = ., ., ., ., ., .
mat sumstat_m = ., ., ., ., ., .


 su drop [w=weight] if surv79==0
 gen float n66 = round(r(N),.0001)
 gen float mn66 = round(r(mean),.0001)
 gen float sd66 = round(r(sd),.0001)
 su n66
 local n66 = r(mean)
 su mn66
 local m66 = r(mean)
 su sd66
 local s66 = r(mean)

 
 su drop [w=weight] if surv79==1
 gen float n79 = round(r(N),.0001)
 gen float mn79 = round(r(mean),.0001)
 gen float sd79 = round(r(sd),.0001)
 su n79
 local n79 = r(mean)
 su mn79
 local m79 = r(mean)
 su sd79
 local s79 = r(mean)
 
 mat sumstat = sumstat \ (`n66', `m66', `s66', `n79', `m79', `s79')
 drop n66 mn66 sd66 n79 mn79 sd79
  
 su drop [w=weight] if surv79==0 & women==1
 gen float n66 = round(r(N),.0001)
 gen float mn66 = round(r(mean),.0001)
 gen float sd66 = round(r(sd),.0001)
 su n66
 local n66 = r(mean)
 su mn66
 local m66 = r(mean)
 su sd66
 local s66 = r(mean)
 
 su drop [w=weight] if surv79==1 & women==1
 gen float n79 = round(r(N),.0001)
 gen float mn79 = round(r(mean),.0001)
 gen float sd79 = round(r(sd),.0001)
 su n79
 local n79 = r(mean)
 su mn79
 local m79 = r(mean)
 su sd79
 local s79 = r(mean)
 
 
 mat sumstat_w = sumstat_w \ (`n66', `m66', `s66', `n79', `m79', `s79')
 drop n66 mn66 sd66 n79 mn79 sd79
 
 su drop [w=weight] if surv79==0 & women==0
 gen float n66 = round(r(N),.0001)
 gen float mn66 = round(r(mean),.0001)
 gen float sd66 = round(r(sd),.0001)
 su n66
 local n66 = r(mean)
 su mn66
 local m66 = r(mean)
 su sd66
 local s66 = r(mean)
 
 su drop [w=weight] if surv79==1 & women==0
 gen float n79 = round(r(N),.0001)
 gen float mn79 = round(r(mean),.0001)
 gen float sd79 = round(r(sd),.0001)
 su n79
 local n79 = r(mean)
 su mn79
 local m79 = r(mean)
 su sd79
 local s79 = r(mean)
 
 mat sumstat_m = sumstat_m \ (`n66', `m66', `s66', `n79', `m79', `s79')
 drop n66 mn66 sd66 n79 mn79 sd79 
 
drop if keep==0


foreach var of varlist  linkDad linkMom linkBoth faminc0 lfaminc0 dad_present dad_age_b mom_present mom_age_b kid_age_parent faminc1 lfaminc1 kid_age spouse_present spouse_age white black nsib weight unemp_parent unemp_kid {
  su `var' [w=weight] if surv79==0
 gen float n66 = round(r(N),.001)
 gen float mn66 = round(r(mean),.001)
 gen float sd66 = round(r(sd),.001)
 su n66
 local n66 = r(mean)
 su mn66
 local m66 = r(mean)
 su sd66
 local s66 = r(mean)

 
 su `var' [w=weight] if surv79==1
 gen float n79 = round(r(N),.001)
 gen float mn79 = round(r(mean),.001)
 gen float sd79 = round(r(sd),.001)
 su n79
 local n79 = r(mean)
 su mn79
 local m79 = r(mean)
 su sd79
 local s79 = r(mean)
 
 mat sumstat = sumstat \ (`n66', `m66', `s66', `n79', `m79', `s79')
 drop n66 mn66 sd66 n79 mn79 sd79
  

}
}

* Low Weight
clear 
svmat sumstat
outsheet using ${results_dir}tableA29_low.csv, comma names replace









clear
use "${data_dir}DavisMazumderData.dta"

keep if age_firstSurvey<=18
drop if miss0 | miss1


replace weight = weight/100000 if survey==1966
replace weight = weight/1000 if survey==1979

gen high_weight = weight>=2.8 if survey==1966
 replace high_weight = weight>=3.6 if survey==1979
 
keep if high_weight==1

gen dad_present = dad_age_b<. 
gen mom_present = mom_age_b<. 
gen spouse_present = spouse_age<.

gen keep =  !((mom_outOfRange==1 & linkMom==1 & !(dad_outOfRange==0 & linkDad==1)) | (dad_outOfRange==1 & linkDad==1 & !(mom_outOfRange==0 & linkMom==1)) | (linkMom==0 & linkDad==0) ) 
gen drop = 1-keep

mat sumstat = ., ., ., ., ., .
mat sumstat_w = ., ., ., ., ., .
mat sumstat_m = ., ., ., ., ., .
quietly {

 su drop [w=weight] if surv79==0
 gen float n66 = round(r(N),.0001)
 gen float mn66 = round(r(mean),.0001)
 gen float sd66 = round(r(sd),.0001)
 su n66
 local n66 = r(mean)
 su mn66
 local m66 = r(mean)
 su sd66
 local s66 = r(mean)

 
 su drop [w=weight] if surv79==1
 gen float n79 = round(r(N),.0001)
 gen float mn79 = round(r(mean),.0001)
 gen float sd79 = round(r(sd),.0001)
 su n79
 local n79 = r(mean)
 su mn79
 local m79 = r(mean)
 su sd79
 local s79 = r(mean)
 
 mat sumstat = sumstat \ (`n66', `m66', `s66', `n79', `m79', `s79')
 drop n66 mn66 sd66 n79 mn79 sd79
  
 su drop [w=weight] if surv79==0 & women==1
 gen float n66 = round(r(N),.0001)
 gen float mn66 = round(r(mean),.0001)
 gen float sd66 = round(r(sd),.0001)
 su n66
 local n66 = r(mean)
 su mn66
 local m66 = r(mean)
 su sd66
 local s66 = r(mean)
 
 su drop [w=weight] if surv79==1 & women==1
 gen float n79 = round(r(N),.0001)
 gen float mn79 = round(r(mean),.0001)
 gen float sd79 = round(r(sd),.0001)
 su n79
 local n79 = r(mean)
 su mn79
 local m79 = r(mean)
 su sd79
 local s79 = r(mean)
 
 
 mat sumstat_w = sumstat_w \ (`n66', `m66', `s66', `n79', `m79', `s79')
 drop n66 mn66 sd66 n79 mn79 sd79
 
 su drop [w=weight] if surv79==0 & women==0
 gen float n66 = round(r(N),.0001)
 gen float mn66 = round(r(mean),.0001)
 gen float sd66 = round(r(sd),.0001)
 su n66
 local n66 = r(mean)
 su mn66
 local m66 = r(mean)
 su sd66
 local s66 = r(mean)
 
 su drop [w=weight] if surv79==1 & women==0
 gen float n79 = round(r(N),.0001)
 gen float mn79 = round(r(mean),.0001)
 gen float sd79 = round(r(sd),.0001)
 su n79
 local n79 = r(mean)
 su mn79
 local m79 = r(mean)
 su sd79
 local s79 = r(mean)
 
 mat sumstat_m = sumstat_m \ (`n66', `m66', `s66', `n79', `m79', `s79')
 drop n66 mn66 sd66 n79 mn79 sd79 
 
drop if keep==0


foreach var of varlist  linkDad linkMom linkBoth weight faminc0 lfaminc0 dad_present dad_age_b mom_present mom_age_b kid_age_parent faminc1 lfaminc1 kid_age spouse_present spouse_age white black nsib weight unemp_parent unemp_kid {
  su `var' [w=weight] if surv79==0
 gen float n66 = round(r(N),.001)
 gen float mn66 = round(r(mean),.001)
 gen float sd66 = round(r(sd),.001)
 su n66
 local n66 = r(mean)
 su mn66
 local m66 = r(mean)
 su sd66
 local s66 = r(mean)

 
 su `var' [w=weight] if surv79==1
 gen float n79 = round(r(N),.001)
 gen float mn79 = round(r(mean),.001)
 gen float sd79 = round(r(sd),.001)
 su n79
 local n79 = r(mean)
 su mn79
 local m79 = r(mean)
 su sd79
 local s79 = r(mean)
 
 mat sumstat = sumstat \ (`n66', `m66', `s66', `n79', `m79', `s79')
 drop n66 mn66 sd66 n79 mn79 sd79
  
 
}
}
* High Weight
matrix list sumstat

clear 
svmat sumstat
outsheet using ${results_dir}tableA29_high.csv, comma names replace

exit
